package com.yuerlive.rainbow.module.mine;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.yuerlive.rainbow.R;
import com.yuerlive.rainbow.base.BaseActivity;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.EditedInfo;
import com.yuerlive.rainbow.module.mine.presenter.EditContract;
import com.yuerlive.rainbow.module.mine.presenter.EditPresenter;
import com.yuerlive.rainbow.utils.ToastUtils;
import com.yuerlive.rainbow.utils.UserProxy;
import com.yuerlive.rainbow.widget.timeselector.TextUtil;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Admin on 2017/6/2.
 */

public class MySignActivity extends BaseActivity implements EditContract.View {
    @BindView(R.id.etContent)
    EditText etContent;
    @BindView(R.id.tvRight)
    TextView tvRight;
    private EditContract.Presenter presenter;
    private EditedInfo info;
    private static final int PERSONSIGNATURE = 5;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_sign;
    }

    @Override
    protected void initViews() {
        presenter = new EditPresenter(this);
        setTitle("个性签名");
        if(UserProxy.getUser()!=null){
            if(TextUtils.isEmpty(UserProxy.getUser().getUserInfo().getPersonalsignature())){
                etContent.setText("");
            }else{
                etContent.setText(UserProxy.getUser().getUserInfo().getPersonalsignature());
            }
        }
        tvRight.setText("保存");
        tvRight.setTextColor(mActivity.getResources().getColor(R.color.input_red));
    }

    @OnClick({R.id.tvRight})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvRight:
                if (!TextUtil.isEmpty(etContent.getText().toString())) {
                    info = new EditedInfo();
                    info.setType(PERSONSIGNATURE);
                    info.setPersonsignature(etContent.getText().toString());
                    presenter.getEditRequest(info);
                } else {
                    ToastUtils.show("请输入个性签名");
                }

                break;
        }
    }

    @Override
    public void showResutl(BaseData baseData, int type) {
        if (baseData.getCode() == 0 && type == PERSONSIGNATURE && info != null) {
            Intent intent = new Intent();
            intent.putExtra("signContent", info.getPersonsignature());
            this.setResult(RESULT_OK, intent);
            this.finish();
        }
    }

    @Override
    public void setPresenter(EditContract.Presenter presenter) {
        super.presenter = presenter;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
